package com.cskaoyan.controller.wx.zjh;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.pojo.MarketUser;
import com.cskaoyan.service.wx.zjh.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/11/10:47
 */
@RestController
@RequestMapping("wx")
public class CollectController {

    @Autowired
    CollectService collectService;

    @PostMapping("collect/addordelete")
    public BaseRespVo collectAddordelete(@RequestBody Map map) {
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();

        Integer type = (Integer) map.get("type");
        Integer valueId = (Integer) map.get("valueId");
        BaseRespVo baseRespVo = collectService.addordelete(marketUser.getId(),type,valueId);
        return baseRespVo;
    }

    @GetMapping("collect/list")
    public BaseRespVo collectList(Integer type, Integer page, Integer limit) {
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer id = marketUser.getId();

        BaseRespVo baseRespVo = collectService.listCollect(id,type, page, limit);
        return baseRespVo;
    }
}
